package cs2340.droidceptiontodo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

/**
 * Date Filter Activity Class
 * Filters by date
 * @author Susmita
 *
 */
public class DateActivity extends Activity implements OnClickListener{
	EditText datepick;
	Button filterdate;
	Button cancelfilterdate;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.date);
		datepick = (EditText)findViewById(R.id.datepicker);
		filterdate = (Button)findViewById(R.id.filterbydate);
		cancelfilterdate = (Button)findViewById(R.id.canceldatefilter);
		filterdate.setOnClickListener(this);
		cancelfilterdate.setOnClickListener(this);
	}
	
	/**
     * If user clicks on filter button, returns successful message
     * If user clicks on cancel, returns back to Filter main page
     * 
     */
	@Override
	public void onClick(View v) {
		if (v.getId()==filterdate.getId()){
			//Database settingsManager = new Database(this);
			Database settingsManager = Database.getInstance(this);
			settingsManager.open();
			settingsManager.setSetting("sortByDate", datepick.getText().toString());
			settingsManager.close();
			finish();
		}
		else if (v.getId()==cancelfilterdate.getId()){
			finish();
		}
	}
	 
}
